package com.kunbo.cn.controller.core.purchase;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kunbo.cn.entity.core.purchase.SaleWaybill;
import com.kunbo.cn.service.core.purchase.SaleWaybillService;
import com.kunbo.cn.util.json.FastJsonUtils;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.CommonResult;
import com.kunbo.cn.util.retu.ResultBean;

@RestController
@RequestMapping("/sale/waybill")
public class SaleWaybillController {
	@Autowired
	private SaleWaybillService waybillService;
	@RequestMapping("/add")
	public CommonResult add(String jsonstr) {
		if(StringUtils.isNotBlank(jsonstr)) {
			return new CommonResult(false,"参数为空",null);
		}
		try {
			SaleWaybill w = FastJsonUtils.toBean(jsonstr, SaleWaybill.class);
			waybillService.save(w);
			return new CommonResult(true,"操作成功",null);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return new CommonResult(false,"数据转换异常，请检测",null);
		}
		
	}
	
	@RequestMapping("/findById")
	public SaleWaybill findById(String id) {
		return waybillService.findById(id);
		
	}

	
	
	@PostMapping("/saleWaybillOrderCount")
	public ResultBean<Boolean> waybillOrderCount(
			@RequestParam("code")String code,
			@RequestParam("count")float count,
			@RequestParam("state")String state
			){
		ResultBean<Boolean>  result   = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "succes", "error", waybillService.waybillOrderCount(code,count,state));
	}
}
